package com.toulezu.test.schedule;

import com.ckjava.xutils.Constants;
import com.ckjava.xutils.DateUtils;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
//@EnableScheduling // 标注启动定时任务
public class SpringSchedule {

	@Scheduled(fixedRate = 1000 * 30) // 30秒执行一次
	public void reportCurrentTime() {
		System.out.println("Scheduling Tasks Examples reportCurrentTime: The time is now " + DateUtils.formatTime(new Date().getTime(), Constants.TIMEFORMAT.DATETIME));
	}

	@Scheduled(cron="*/10 * * * * ?") // 每10秒执行一次
	public void reportCurrentTimeByCron() {
		System.out.println("Scheduling Tasks Examples reportCurrentTimeByCron: The time is now " + DateUtils.formatTime(new Date().getTime(), Constants.TIMEFORMAT.DATETIME));
	}
}